﻿/*
Copyright (c) 2013, Douglas Stebila, Brendon Park, David Sweeney, Nathan Wills, Simon Lockhart, Thomas Phan
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
  list of conditions and the following disclaimer in the documentation and/or
  other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.IO;
using System.Security.Cryptography;


namespace NMLE
{
    /// <summary>
    ///     Interface providing members for all message locked algorythms
    /// </summary>
    public interface IMessageLockedAlgorithm
    {
        /// <summary>
        ///     Gets or sets the block size, in bits, of the cryptographic
        ///     operation.
        /// </summary>
        int BlockSize
        {
            get;
            set;
        }

        /// <summary>
        ///     Gets or sets the feedback size, in bits, of the cryptographic
        ///     operation.
        /// </summary>
        int FeedbackSize
        {
            get;
            set;
        }

        /// <summary>
        ///     Gets or sets the keysize used
        /// </summary>
        Int32 KeySize { get; set; }

        /// <summary>
        ///     Gets the key sizes, in bits, that are supported by the
        ///     symmetric algorithm.
        /// </summary>
        KeySizes[] LegalKeySizes
        {
            get;
        }

        /// <summary>
        ///     Gets the mode for operation of the symmetric algorithm.
        /// </summary>
        CipherMode Mode
        {
            get;
            set;
        }

        /// <summary>
        ///     Gets the padding mode used in the symmetric algorithm.
        /// </summary>
        PaddingMode Padding
        {
            get;
            set;
        }

        /// <summary>
        ///     Creates a message locked decryptor object with the current
        ///     key, hash algorythm and, symetric algorythm.
        /// </summary>
        /// <returns>
        ///     A message locked decryptor object.
        /// </returns>
        ICryptoTransform GetDecryptor();

        /// <summary>
        ///     Creates a message locked encryptor object with the current
        ///     hash algorythm and symetric algorythm.
        /// </summary>
        /// <returns>
        /// </returns>
        ICryptoTransform GetEncryptor();

        /// <summary>
        ///     Gets the MLE key for the given message     
        /// </summary>
        /// <param name="message">
        ///     Stream containing the message that will be encrypted
        /// </param>
        /// <param name="keySize">
        ///     A valid keysize to truncate the key too
        /// </param>
        void DeriveKey(Stream message, Int32 keySize);

        /// <summary>
        ///     Gets the MLE key for the given message
        /// </summary>
        /// <param name="message">
        ///     Stream containing the message that will be encrypted
        /// </param>
        void DeriveKey(Stream message);

        /// <summary>
        ///     Gets or sets the secret key for the message locked crypto
        ///     algorithm.
        /// </summary>
        byte[] Key
        {
            get;
            set;
        }

        /// <summary>
        ///     Gets the expected tag for the supplied TransformKey
        /// </summary>
        byte[] Tag
        {
            get;
        }

        /// <summary>
        ///     Performs application-defined tasks associated with freeing,
        ///     releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        void Dispose();

        /// <summary>
        ///     Get a value indicating the largest legal keysize
        /// </summary>
        /// <returns>
        ///     The largest legal keysize
        /// </returns>
        Int32 LargestValidKey();
    }
}
